/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2010.

	This file is part of the Maxsi Library.

	Maxsi Library is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi Library is distributed in the hope that it will be useful, but
	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
	or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
	License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Library. If not, see <http://www.gnu.org/licenses/>.

	Maxsi Library
	A powerful Cross-Platform C++ General Purpose Library that allows you to
	efficiently create high-performance and reliable applications.

	MaxsiWindowW32.h
	Implements the MaxsiWindowSystem using the W32 platform.

******************************************************************************/

#ifndef MaxsiWindowW32_H
#define MaxsiWindowW32_H

BeginMaxsiNamespace

//=============================================================================
//	Forward declarations.
//=============================================================================
class MaxsiControlSystemW32;
class MaxsiWindowW32;
class MaxsiWindowSystemW32;

//=============================================================================
//	Redirect a number of Windows specific functions depending on whether we are
//	using Unicode in this build, or just plain old ASCII. Technically, I don't
//	see any reason to use the ASCII versions any longer - not even for
//	compabillity with old code that is long gone - but it's always nice to know
//	this works, if any program using our library is using ASCII.
//=============================================================================
#ifdef Maxsi_Using_Unicode_Internally

	#define SendMessageM SendMessageW
	#define CreateWindowM CreateWindowW
	#define GetWindowLongM GetWindowLongW
	#define WSAAddressToStringM WSAAddressToStringW
	#define FormatMessageM FormatMessageW
	#define WNDCLASSM WNDCLASSW
	#define RegisterClassM RegisterClassW
	#define MessageBoxM MessageBoxW
	#define CreateFontM CreateFontW
	#define SetWindowTextM SetWindowTextW
	#define DefWindowProcM DefWindowProcW
	#define GetMessageM GetMessageW
	#define DispatchMessageM DispatchMessageW
	#define LoadImageM LoadImageW

#else

	#define SendMessageM SendMessageA
	#define CreateWindowM CreateWindowA
	#define GetWindowLongM GetWindowLongA
	#define WSAAddressToStringM WSAAddressToStringA
	#define FormatMessageM FormatMessageA
	#define WNDCLASSM WNDCLASSA
	#define RegisterClassM RegisterClassA
	#define MessageBoxM MessageBoxA
	#define CreateFontM CreateFontA
	#define SetWindowTextM SetWindowTextA
	#define DefWindowProcM DefWindowProcA
	#define GetMessageM GetMessageA
	#define DispatchMessageM DispatchMessageA
	#define LoadImageM LoadImageA

#endif

//=============================================================================
//	TODO: This will most likely not be used, so go delete this soon.
//=============================================================================
MAXSI_STRUCTLINK MaxsiWindowSystemW32HandleList
{
	HWND			WindowHandle;
	MaxsiWindow*	WindowClass;
};

//=============================================================================
//	Define where the MaxsiWindowSystemW32 interface is declared.
//=============================================================================
#undef MAXSI_INTERFACE
#define MAXSI_INTERFACE MAXSI_INTERFACE_IMPLEMENTED_IN_MAXSI_LIBRARY

//=============================================================================
//	MaxsiWindowSystemW32 - Implements MaxsiWindowSystem using W32+.
//=============================================================================
MAXSI_CLASSLINK MaxsiWindowSystemW32 : public MaxsiWindowSystem
{
public:
	MaxsiWindowSystemW32();
	~MaxsiWindowSystemW32();

public:
	//=============================================================================
	//	MaxsiControlSystem* GetControlSystem();
	//
	//	Returns a pointer to a class that can create and handle controls on this
	//	kind of Maxsi Window System.
	//=============================================================================
	virtual MaxsiControlSystem* GetControlSystem() MAXSI_INTERFACE;
	
	//=============================================================================
	//	MaxsiControlSystem* CreateControlSystem();
	//
	//	Allocates a new instance of the control system for this window system.
	//=============================================================================
	virtual MaxsiControlSystem* CreateControlSystem() MAXSI_INTERFACE;
	
	//=============================================================================
	//	bool DeleteControlSystem(MaxsiControlSystem* ControlSystem);
	//
	//	Deallocates an instance of the control system for this window system.
	//=============================================================================
	virtual bool DeleteControlSystem(MaxsiControlSystem* ControlSystem) MAXSI_INTERFACE;

	//=============================================================================
	//	int Initialize(int* argc, int** argv);
	//	
	//	Initializes this Window System if it hasn't already been initialized. From
	//	this point on it is perfectly safe to use this Window System to create
	//	MaxsiWindows with. This function is allowed to change argc and argv.
	//=============================================================================
	virtual int Initialize(int* argc, char*** argv) MAXSI_INTERFACE;

	//=============================================================================
	//	int MainLoop();
	//
	//	Runs the mainloop code for this kind of Window System.
	//=============================================================================
	virtual int MainLoop() MAXSI_INTERFACE;

	//=============================================================================
	//	MaxsiHandle CreateWindow(MaxsiHandle Parent, int Width, int Height,
	//	int Left, int Top, MESTR* Title);
	//
	//	Creates a new window using this window system and returns a handle to the
	//	Window. Returns NULL upon failure.
	//=============================================================================
	virtual MaxsiHandle CreateWindow(MaxsiHandle Parent, int Width, int Height, int Left, int Top, MESTR* Title) MAXSI_INTERFACE;

	//=============================================================================
	//	bool ShowWindow(MaxsiHandle Window);
	//
	//	Changes the visibillity of the Window pointed to by the handle.
	//=============================================================================
	virtual bool ShowWindow(MaxsiHandle Window) MAXSI_INTERFACE;

	//=============================================================================
	//	bool HideWindow(MaxsiHandle Window);
	//
	//	Changes the visibillity of the Window pointed to by the handle.
	//=============================================================================
	virtual bool HideWindow(MaxsiHandle Window) MAXSI_INTERFACE;

	//============================================================================
	//	MaxsiHandle CreatePictureBufferFromFile(MESTR* FileName);
	//
	//	Returns a picture buffer containing the image data found in FileName.
	//	Call DeletePictureBuffer when done with the pictue buffer.
	//============================================================================
	virtual MaxsiHandle CreatePictureBufferFromFile(MESTR* FileName) MAXSI_INTERFACE;

	//============================================================================
	//	bool DeletePictureBuffer(MaxsiHandle PictureBuffer);
	//
	//	Deletes a previously allocated picture buffer and returns true. Or it
	//	returns false and fills your computer with memory leaks.
	//============================================================================
	virtual bool DeletePictureBuffer(MaxsiHandle PictureBuffer) MAXSI_INTERFACE;

	//============================================================================
	//	bool DeletePictureBuffer(MaxsiHandle PictureBuffer);
	//
	//	Deletes a picture buffer allocated using CreatePictureBuffer*().
	//============================================================================
	virtual bool SetWindowIcon(MaxsiHandle Window, MaxsiHandle Icon) MAXSI_INTERFACE;

	//=============================================================================
	//	int MoveWindowControl(MaxsiHandle Control, int Left, int Top, int Width, int 
	//	Height, bool UnusedInLinux);
	//
	//	Sets the location and size of a control on this Maxsi Window.
	//=============================================================================
	virtual int MoveWindowControl(MaxsiHandle Parent, MaxsiHandle Control, int Left, int Top, int Width, int Height, bool UnusedInLinux) MAXSI_INTERFACE;

	virtual int MsgBox(MaxsiHandle Parent, int Flags, MESTR* Message, MESTR* Title) MAXSI_INTERFACE;

	virtual MaxsiError GetWindowSize(MaxsiHandle Window, int* Left, int* Top, int* Width, int* Height) MAXSI_INTERFACE;

	virtual MaxsiError UpdateWindow(MaxsiHandle Window) MAXSI_INTERFACE;

	virtual MaxsiHandle GetDefaultBoldFont() MAXSI_INTERFACE;

};

//=============================================================================
//	Define where the MaxsiControlSystemW32 interface is declared.
//=============================================================================
#undef MAXSI_INTERFACE
#define MAXSI_INTERFACE MAXSI_INTERFACE_IMPLEMENTED_IN_MAXSI_LIBRARY

//=============================================================================
//	MaxsiControlSystemW32 - Implements MaxsiControlSystem using W32+.
//=============================================================================
MAXSI_CLASSLINK MaxsiControlSystemW32 : public MaxsiControlSystem
{
public:
	//=============================================================================
	//	bool DeleteControl(MaxsiHandle Control);
	//
	//	Deletes a control from its parent and clears memory, whatsoever!
	//=============================================================================
	virtual bool DeleteControl(MaxsiHandle Control) MAXSI_INTERFACE;

	//=============================================================================
	//	MaxsiHandle CreateControlType(MaxsiHandle Parent);
	//	
	//	Creates a control of the type ControlType on the MaxsiWindow* Parent.
	//=============================================================================
	virtual MaxsiHandle CreateFrame(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateLabel(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateButton(MaxsiHandle Parent) MAXSI_INTERFACE;	
	virtual MaxsiHandle CreateTextSingleLine(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateTextMultiLine(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateRadioButton(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateCheckButton(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateProgressBar(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateTreeView(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateListView(MaxsiHandle Parent) MAXSI_INTERFACE;
	virtual MaxsiHandle CreateSeparatorH(MaxsiHandle Parent) MAXSI_INTERFACE;

	virtual bool SetLabelText(MaxsiHandle Control, MESTR* Text) MAXSI_INTERFACE;
	virtual bool SetLabelFont(MaxsiHandle Control, MaxsiHandle Font) MAXSI_INTERFACE;
	virtual bool SetButtonText(MaxsiHandle Control, MESTR* Text) MAXSI_INTERFACE;
	virtual bool SetProgress(MaxsiHandle Control, float Progress, size_t Type) MAXSI_INTERFACE;
	
};

//=============================================================================
//	Remember to reset MAXSI_INTERFACE when done with it for safety reasons.
//=============================================================================
#undef MAXSI_INTERFACE
#define MAXSI_INTERFACE MAXSI_INTERFACE_ABSTRACT_BASECLASS

MAXSI_LINK MaxsiWindow* HWND2WindowClass(HWND WindowHandle);

EndMaxsiNamespace

#endif

